#ifndef _DSWONVIF_CLIENT_H
#define _DSWONVIF_CLIENT_H
#include <libbase/dswbase.h>

typedef struct{
	pthread_mutex_t nLock;
	HashTable* pDescoverResult;
} ST_EXTCAM_RESULT_T, *LPST_EXTCAM_RESULT_T;

class CDswonvif_client : public CDswbase
{
public:
	CDswonvif_client(LPST_ENV_T pEnv);
	virtual ~CDswonvif_client();
public:
	static LPST_ASYNCHRONOUS_CMD_T cbExtCamDescover(LPST_ASYNCHRONOUS_CMD_T pCmd, void* pCaller){return ((CDswonvif_client*)pCaller)->ExtCamDescover(pCmd);};
	static LPST_ASYNCHRONOUS_CMD_T cbExtCamPrepare(LPST_ASYNCHRONOUS_CMD_T pCmd, void* pCaller){return ((CDswonvif_client*)pCaller)->ExtCamPrepare(pCmd);};
	static LPST_ASYNCHRONOUS_CMD_T cbExtCamPTZCtrl(LPST_ASYNCHRONOUS_CMD_T pCmd, void* pCaller){return ((CDswonvif_client*)pCaller)->ExtCamPTZCtrl(pCmd);};
	static LPST_ASYNCHRONOUS_CMD_T cbExtCamSyncTm(LPST_ASYNCHRONOUS_CMD_T pCmd, void* pCaller){return ((CDswonvif_client*)pCaller)->ExtCamSyncTm(pCmd);};
	static LPST_ASYNCHRONOUS_CMD_T cbExtCamCheck(LPST_ASYNCHRONOUS_CMD_T pCmd, void* pCaller){return ((CDswonvif_client*)pCaller)->ExtCamCheck(pCmd);};

private:
	LPST_ASYNCHRONOUS_CMD_T GetCmdNodeWithCmd(EN_MSG_TYPE nMsgType, LPLIST_ASYNCHRONOUS_CMD_T pList);
	LPST_ASYNCHRONOUS_CMD_T GetCmdNode(LPLIST_ASYNCHRONOUS_CMD_T pList);
	void PutCmdNode(LPLIST_ASYNCHRONOUS_CMD_T pList, LPST_ASYNCHRONOUS_CMD_T pNode);

	static void* cbProcessExtcamCmdThreadFunc(void* pParam){((CDswonvif_client*)pParam)->ProcessExtcamCmdThreadFunc();return NULL;};
	void ProcessExtcamCmdThreadFunc();

	static void cbCheckNetworkReadyTask(int fd, short events, void* ctx){((CDswonvif_client*)ctx)->CheckNetworkReadyTask(fd, events);};
	void CheckNetworkReadyTask(int fd, short events);

	LPST_ASYNCHRONOUS_CMD_T ExtCamDescover(LPST_ASYNCHRONOUS_CMD_T pCmd);
	LPST_ASYNCHRONOUS_CMD_T ExtCamPrepare(LPST_ASYNCHRONOUS_CMD_T pCmd);
	LPST_ASYNCHRONOUS_CMD_T ExtCamPTZCtrl(LPST_ASYNCHRONOUS_CMD_T pCmd);
	LPST_ASYNCHRONOUS_CMD_T ExtCamSyncTm(LPST_ASYNCHRONOUS_CMD_T pCmd);
	LPST_ASYNCHRONOUS_CMD_T ExtCamCheck(LPST_ASYNCHRONOUS_CMD_T pCmd);
	
	bool MakeOnvifCapbility(LPST_EXTERNAL_CAM_T pExtcam);
	bool GetProfiles(void* psoap, LPST_EXTERNAL_CAM_T pExtcam, char* pMediaURL);
	bool SetStreamGOV(void* psoap, LPST_EXTERNAL_CAM_T pExtcam, char* pMediaURL, struct tt__VideoEncoderConfiguration*  Configuration);
	bool GetStreamURL(void* psoap, LPST_EXTERNAL_CAM_T pExtcam, char* pMediaURL, char* profile_token, char* pStreamURL);
	void ExecuteOnvifPTZAction(LPST_EXTERNAL_CAM_T pExtcam, LPST_APP_PTZ_T pAppPTZ);
	bool GetCamTime(LPST_EXTERNAL_CAM_T pExtcam, time_t &nTime, bool &bDaylightSavings);
	void SetCamTime(LPST_EXTERNAL_CAM_T pExtcam, time_t nTime, bool bDaylightSavings);

	bool GetDeviceInformation(char* pURL, char* pKey);
private:
	virtual int OnMessage(EN_MSG_TYPE nMsgType, void * pParam);
private:
	ST_ASYNC_CMD_T m_nAsyncCmd;
	ST_EXTCAM_RESULT_T m_nExtCamResult;
	ST_ETH_PARAM_T m_nEthParam;
	ST_TIMER_PARAM_T m_nCheckNetworkReadyTask;
};


#endif

